//
//  QrCodeView.m
//  yixintong
//
//  Created by longzhiyuan on 15/5/18.
//
//

#import "QrCodeView.h"

@implementation QrCodeView

- (instancetype)init
{
    self = [super init];
    if (self) {
        
    }
    return self;
}
-(instancetype)initWithFrame:(CGRect)frame
{
    NSLog(@"QrCodeView.h===initWithFrame==");
    [super initWithFrame:frame];
    self.backgroundColor = [UIColor blackColor];
    self.alpha=0.8;
    NSString* qrCodeStr = [[NSUserDefaults standardUserDefaults]objectForKey:@"qrCodeStr"];
    NSThread* thread2=[[NSThread alloc]initWithTarget:self selector:@selector(downloadQrcodeIm:) object:qrCodeStr];
    [thread2 start];
    [thread2 release];
    return self;
}
-(void)dealloc
{
    self.qrCodeView = nil;
    [super dealloc];
}
-(void)downloadQrcodeIm:(NSString*)url
{
    NSLog(@"url====%@",url);
    @synchronized(url)
    {
        NSURL* qrCodeUrl=[NSURL URLWithString:url];
        NSData* qrCodeData=[NSData dataWithContentsOfURL:qrCodeUrl];
        NSLog(@"qrCodeStr=====%@",qrCodeData);
        if (qrCodeData!=nil)
        {
            self.qrCodeView=[[[UIImageView alloc]initWithFrame:CGRectMake(100, 120, 120, 120)]autorelease];
            self.qrCodeView.image=[UIImage imageWithData:qrCodeData];
            [self addSubview:self.qrCodeView];
        }
        
    }
}

@end
